Analysis of Branch Misses in Quicksort
نویسندگان
چکیده
The analysis of algorithms mostly relies on counting classic elementary operations like additions, multiplications, comparisons, swaps etc. This approach is often sufficient to quantify an algorithm’s efficiency. In some cases, however, features of modern processor architectures like pipelined execution and memory hierarchies have significant impact on running time and need to be taken into account to get a reliable picture. One such example is Quicksort: It has been demonstrated experimentally that under certain conditions on the hardware the classically optimal balanced choice of the pivot as median of a sample gets harmful. The reason lies in mispredicted branches whose rollback costs become dominating. In this paper, we give the first precise analytical investigation of the influence of pipelining and the resulting branch mispredictions on the efficiency of (classic) Quicksort and Yaroslavskiy’s dual-pivot Quicksort as implemented in Oracle’s Java 7 library. For the latter it is still not fully understood why experiments prove it 10 % faster than a highly engineered implementation of a classic single-pivot version. For different branch prediction strategies, we give precise asymptotics for the expected number of branch misses caused by the aforementioned Quicksort variants when their ∗Part of this research was done during a visit at UPC, for which the second and third authors acknowledge support by project TIN2007-66523 Formal methods and algorithms for system design (FORMALISM) of the Spanish Ministry of Economy and Competitiveness †Department of Computer Science, Univ. Politècnica de Catalunya, Email: [email protected] ‡Computer Science Department, University of Kaiserslautern, Email: {wild,nebel}@cs.uni-kl.de §Department of Mathematics and Computer Science, University of Southern Denmark pivots are chosen from a sample of the input. We conclude that the difference in branch misses is too small to explain the superiority of the dual-pivot algorithm.
منابع مشابه
Sorting in the Presence of Branch Prediction and Caches Fast Sorting on Modern Computers
Sorting is one of the most important and studied problems in computer science. Many good algorithms exist which offer various trade-offs in efficiency, simplicity and memory use. However most of these algorithms were discovered decades ago at a time when computer architectures were much simpler than today. Branch prediction and cache memories are two developments in computer architecture that h...
متن کاملDeriving Limits of Branch Prediction with the Fano Inequality
Information theory provides tools and techniques to measure the fundamental limits of predictability. Apart from this formal basis, researchers have attempted to construct so-called ‘optimal’ predictors in order to conduct limits studies for different aspects of program predictability (such as branch outcomes and method return values). This paper reports on two case studies for branch predictio...
متن کاملHow Branch Mispredictions Affect Quicksort
We explain the counterintuitive observation that finding “good” pivots (close to the median of the array to be partitioned) may not improve performance of quicksort. Indeed, an intentionally skewed pivot improves performance. The reason is that while the instruction count decreases with the quality of the pivot, the likelihood that the direction of a branch is mispredicted also goes up. We anal...
متن کاملImproving Memory Performance
Memory hierarchy considerations during sorting algorithm design and implementation play an important role in signiicantly improving execution performance. Existing algorithms mainly attempt to reduce capacity misses on direct-mapped caches. In order to further exploit cache locality to reduce other types of cache misses, we present several restructured mergesort and quicksort algorithms and the...
متن کاملBranch Mispredictions Don't Affect Mergesort
In quicksort, due to branch mispredictions, a skewed pivotselection strategy can lead to a better performance than the exactmedian pivot-selection strategy, even if the exact median is given for free. In this paper we investigate the effect of branch mispredictions on the behaviour of mergesort. By decoupling element comparisons from branches, we can avoid most negative effects caused by branch...
متن کامل